define(['jquery', 'table'], function ($, Table) {
	var c = {
		test: function () {
			console.log('Hello World!');
		},
		// var func = throttle(function(){}, 1000);
		throttle(func, delay) {
			let timer = null;
			return function () {
				const context = this;
				const args = arguments;
				if (!timer) {
					timer = setTimeout(function () {
						func.apply(context, args);
						timer = null;
					}, delay);
				}
			};
		},
		debounce(func, wait) {
			let timeout;
			return function executedFunction(...args) {
				const later = () => {
					clearTimeout(timeout);
					func(...args);
				};
				clearTimeout(timeout);
				timeout = setTimeout(later, wait);
			};
		},
		xc_tab_processfield(fieldname) {
			var xc_tabid = $("#xc_tabid", window.parent.document).val();
			$("#c-" + fieldname).val(xc_tabid); //xcframework
			$("#c-" + fieldname).attr("disabled", "true");
			$("#c-" + fieldname).after("<input type='hidden' name='row[" + fieldname + "]' value='" + xc_tabid + "'>");
		},
		openWindow(url) {
			var that = this;
			window.open(url);
		},
		/**
			[HTML]
			<button type="submit" id="saveBtn" class="btn btn-primary btn-embossed disabled">保存</button>
            <button type="submit" id="submitBtn" class="btn btn-success btn-embossed disabled">提交</button>
			[JS]
			xcore.bindSubmitEvent(Form, "edit-form", "saveBtn", "submitBtn");
			[Controller]
			protected function beforeCreateOrUpdateSaveSubmit(&$params){}
			protected function beforeCreateOrUpdateSubmitSubmit(&$params){}
			protected function afterCreateOrUpdateSaveSubmit($row){}
			protected function afterCreateOrUpdateSubmitSubmit($row){}
		 */
		bindSubmitEvent(Form, formId, saveBtnId, submitBtnId, func) {
			var that = this;
			var jqForm = $("#" + formId);

			$("#" + saveBtnId).click(function () {
				var action = "save";
				if ($("input[name=xc_action]").length == 0) {
					$("form[role=form]").append("<input type='hidden' name='xc_action' value='" + action + "'/>");
				} else {
					$("input[name=xc_action]").val(action);
				}
				jqForm.validator({
					timely: 0
				});
			});
			$("#" + submitBtnId).click(function () {
				var action = "submit";
				if ($("input[name=xc_action]").length == 0) {
					$("form[role=form]").append("<input type='hidden' name='xc_action' value='" + action + "'/>");
				} else {
					$("input[name=xc_action]").val(action);
				}
			});

			Form.api.bindevent(jqForm, function (data, ret) {
				window.location = "edit/ids/" + data['row']['id'] + "?dialog=1";
				return false;
			});
		}
	};
	return c;
});